package cn.lizemin.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author lzm
 * @Date 2024/8/4
 * @description
 */
@WebServlet("/servletA")
public class ServletA extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("servletA执行了");
        // 将请求转发给servletB
//        RequestDispatcher dispatcher = req.getRequestDispatcher("servletB");

        // 将请求转发给视图, springMVC的视图转发的底层就是利用了这行代码实现
//        RequestDispatcher dispatcher = req.getRequestDispatcher("hello.html");
        RequestDispatcher dispatcher = req.getRequestDispatcher("WEB-INF/girl.jpg");

        String name = req.getParameter("name");
        System.out.println("servlet A:name = " + name);
        // 将请求转发给servletB，其实就类似于调用servletB中的方法
        dispatcher.forward(req, resp);
    }

}
